package com.example.visitmanage.adapter

import android.widget.TextView

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_base.BaseApp
import com.example.lib_base.entity.VisisterBean
import com.example.lib_base.entity.VisisterBeanItem
import com.example.visitmanage.R

class VisisterAdapter:BaseQuickAdapter<VisisterBeanItem,BaseViewHolder>(R.layout.item_visister){
    override fun convert(helper: BaseViewHolder, item: VisisterBeanItem) {
        helper.setText(R.id.tv_time, item.appointmentTime)
            .setText(R.id.tv_name, item.visitorName)
            .setText(R.id.tv_reason, "来访事由：${item.purpose}")
            .setText(R.id.tv_target, "访问对象：${item.employeeId}")
            .setText(R.id.tv_status, "${item.visitStatus}")
            .setText(R.id.tv_phone, "${item.phoneNumber}")

        // 2. 绑定车位信息（可选字段处理）
        helper.setText(R.id.tv_parking, if(item.approved)  "已申请访客车位" else "未申请访客车位")
        helper.getView<TextView>(R.id.tv_parking).setTextColor(
            if(item.approved)  BaseApp.context.resources.getColor(R.color.blue)
            else BaseApp.context.resources.getColor(R.color.gray))

        // 3. 绑定状态（根据状态值设置不同颜色）
        when (item.visitStatus) {
            "已通过" -> {
                helper.getView<TextView>(R.id.tv_status).setTextColor(BaseApp.context.resources.getColor(R.color.green))
                helper.getView<TextView>(R.id.tv_status).setBackgroundResource(R.drawable.xianxianllllln)

            }
            "待审核" -> {
                helper.getView<TextView>(R.id.tv_status).setTextColor(BaseApp.context.resources.getColor(R.color.orange))
                helper.getView<TextView>(R.id.tv_status).setBackgroundResource(R.drawable.xinllllln)

            }
            "已拒绝" -> {
                helper.getView<TextView>(R.id.tv_status).setTextColor(BaseApp.context.resources.getColor(R.color.gray))
                helper.getView<TextView>(R.id.tv_status).setBackgroundResource(R.drawable.xianxiannnnnn)

            }
        }

//        // 4. 绑定电话号码（点击事件处理）
//        helper.setText(R.id.tv_phone, item.phoneNumber)
//            .setOn(R.id.tv_phone) // 添加点击事件

    }

}